#include <iostream>
#include <chrono>
#include <random>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#define VNAME(name) (#name)
#define debug(x) {int debugx = x; std::cout << " (" << VNAME(x) << ": " << (debugx) << ")\n";}
#define F_(n) cout << fixed << setprecision(n)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
bool _linux_Flag;
int maxn;
LL solve(int n) {
    LL a, b, as = 0, bs = 0, ans = 0;
    for (int i = 1; i <= n; ++ i) {
        scanf("%lld %lld", &a, &b);
        if (min(a, b) >= max(as, bs)) ans += min(a, b) - max(as, bs) + (as != bs ? 1ll : 0);
        as = a, bs = b;
    }
    return ans;
}
signed main() {
    #ifndef ONLINE_JUDGE
		_linux_Flag = true; //freopen("C:\\Users\\lenovo\\Desktop\\in.in", "r", stdin);
	#endif
    int t = 1;
    //cin >> t;
    while (t --) {
        int n;
        scanf("%d", &n);
        //solve();
        printf("%lld", solve(n));
        //debug(solve(n));
    }
    #ifndef ONLINE_JUDGE
		system("pause");
	#endif
    return 0;
}